﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D07_Ray2 : MonoBehaviour
{
    public LayerMask layer = -1;//层  -1表示所有层
    public GameObject danHengPrefab;
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var camTf = Camera.main.transform;
            RaycastHit hitInfo;
            if (Physics.Raycast(camTf.position, camTf.forward, out hitInfo, 1000, layer))
            {
                Vector3 pos = hitInfo.point + hitInfo.normal * 0.001f;

                Instantiate(danHengPrefab, pos, Quaternion.LookRotation(-hitInfo.normal));
            }
        }
    }
}